<template>
  <div class="loading-container">
    <div class="loading-content">
      <div class="ai-brain">
        <div class="brain-circle">
          <div class="neural-network">
            <div class="neuron" v-for="i in 8" :key="i" :style="{ '--delay': i * 0.1 + 's' }"></div>
          </div>
        </div>
        <div class="pulse-ring" v-for="i in 3" :key="i" :style="{ '--delay': i * 0.5 + 's' }"></div>
      </div>
      
      <h2 class="loading-title">AI正在生成3D模型</h2>
      <p class="loading-subtitle">{{ currentMessage }}</p>
      
      <div class="progress-container">
        <div class="progress-bar">
          <div class="progress-fill" :style="{ width: progress + '%' }"></div>
        </div>
        <span class="progress-text">{{ progress }}%</span>
      </div>
      
      <div class="loading-tips">
        <p>💡 提示：生成过程可能需要1-3分钟，请耐心等待</p>
        <p>🎨 您可以尝试不同的描述词来获得更好的效果</p>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'LoadingAnimation',
  props: {
    progress: {
      type: Number,
      default: 0
    }
  },
  data() {
    return {
      messages: [
        '正在分析您的描述...',
        'AI正在理解您的需求...',
        '开始生成3D模型...',
        '优化模型细节...',
        '添加材质和纹理...',
        '进行最终渲染...',
        '即将完成...'
      ],
      currentMessageIndex: 0,
      messageInterval: null
    }
  },
  computed: {
    currentMessage() {
      return this.messages[this.currentMessageIndex]
    }
  },
  mounted() {
    this.startMessageRotation()
  },
  beforeUnmount() {
    if (this.messageInterval) {
      clearInterval(this.messageInterval)
    }
  },
  methods: {
    startMessageRotation() {
      this.messageInterval = setInterval(() => {
        this.currentMessageIndex = (this.currentMessageIndex + 1) % this.messages.length
      }, 2000)
    }
  }
}
</script>

<style scoped>
.loading-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.loading-content {
  text-align: center;
  color: white;
  max-width: 500px;
  padding: 40px;
}

.ai-brain {
  position: relative;
  width: 120px;
  height: 120px;
  margin: 0 auto 40px;
}

.brain-circle {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: linear-gradient(45deg, #ff6b6b, #4ecdc4, #45b7d1, #96ceb4);
  background-size: 400% 400%;
  animation: gradientShift 3s ease infinite;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  overflow: hidden;
}

@keyframes gradientShift {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

.neural-network {
  position: relative;
  width: 60px;
  height: 60px;
}

.neuron {
  position: absolute;
  width: 8px;
  height: 8px;
  background: white;
  border-radius: 50%;
  animation: pulse 1.5s ease-in-out infinite;
  animation-delay: var(--delay);
}

.neuron:nth-child(1) { top: 0; left: 50%; transform: translateX(-50%); }
.neuron:nth-child(2) { top: 20%; right: 0; }
.neuron:nth-child(3) { top: 50%; right: 10%; }
.neuron:nth-child(4) { bottom: 20%; right: 0; }
.neuron:nth-child(5) { bottom: 0; left: 50%; transform: translateX(-50%); }
.neuron:nth-child(6) { bottom: 20%; left: 0; }
.neuron:nth-child(7) { top: 50%; left: 10%; }
.neuron:nth-child(8) { top: 20%; left: 0; }

@keyframes pulse {
  0%, 100% { 
    opacity: 0.3; 
    transform: scale(0.8); 
  }
  50% { 
    opacity: 1; 
    transform: scale(1.2); 
  }
}

.pulse-ring {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 100%;
  height: 100%;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  animation: pulseRing 2s ease-out infinite;
  animation-delay: var(--delay);
}

@keyframes pulseRing {
  0% {
    transform: translate(-50%, -50%) scale(0.8);
    opacity: 1;
  }
  100% {
    transform: translate(-50%, -50%) scale(1.4);
    opacity: 0;
  }
}

.loading-title {
  font-size: 28px;
  font-weight: 600;
  margin: 0 0 16px 0;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.loading-subtitle {
  font-size: 18px;
  margin: 0 0 30px 0;
  opacity: 0.9;
  min-height: 24px;
  transition: opacity 0.3s ease;
}

.progress-container {
  margin: 30px 0;
  display: flex;
  align-items: center;
  gap: 15px;
}

.progress-bar {
  flex: 1;
  height: 8px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #4ecdc4, #45b7d1);
  border-radius: 4px;
  transition: width 0.3s ease;
  position: relative;
}

.progress-fill::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
  animation: shimmer 2s infinite;
}

@keyframes shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

.progress-text {
  font-size: 16px;
  font-weight: 600;
  min-width: 40px;
}

.loading-tips {
  margin-top: 40px;
  text-align: left;
}

.loading-tips p {
  margin: 8px 0;
  font-size: 14px;
  opacity: 0.8;
  line-height: 1.5;
}

@media (max-width: 768px) {
  .loading-content {
    padding: 20px;
    max-width: 90%;
  }
  
  .loading-title {
    font-size: 24px;
  }
  
  .loading-subtitle {
    font-size: 16px;
  }
  
  .ai-brain {
    width: 100px;
    height: 100px;
    margin-bottom: 30px;
  }
}
</style>
